package com.spic.business.safetyactivity.service.impl;

import java.util.List;

import com.spic.business.common.datascope.anotation.BusinessDataScope;
import com.spic.common.core.domain.R;
import com.spic.common.core.utils.DateUtils;
import com.spic.system.api.RemoteUserService;
import com.spic.system.api.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.spic.business.safetyactivity.mapper.SafetyActivityMapper;
import com.spic.business.safetyactivity.domain.SafetyActivity;
import com.spic.business.safetyactivity.service.ISafetyActivityService;

/**
 * 安全活动记录Service业务层处理
 * 
 * @author spic
 * @date 2022-06-14
 */
@Service
public class SafetyActivityServiceImpl implements ISafetyActivityService 
{
    @Autowired
    private SafetyActivityMapper safetyActivityMapper;
    @Autowired
    private RemoteUserService remoteUserService;

    /**
     * 查询安全活动记录
     * 
     * @param id 安全活动记录主键
     * @return 安全活动记录
     */
    @Override
    public SafetyActivity selectSafetyActivityById(Long id)
    {
        SafetyActivity safetyActivity = safetyActivityMapper.selectSafetyActivityById(id);
//        R<SysUser> user = remoteUserService.getUserById(Long.valueOf(safetyActivity.getCompere()));
//        safetyActivity.setCompere(user.getData().getNickName());
        return safetyActivity;
    }

    /**
     * 查询安全活动记录列表
     * 
     * @param safetyActivity 安全活动记录
     * @return 安全活动记录
     */
    @BusinessDataScope(menuPath = "business/informatization/safetyActivity/index")
    @Override
    public List<SafetyActivity> selectSafetyActivityList(SafetyActivity safetyActivity)
    {
        List<SafetyActivity> safetyActivities = safetyActivityMapper.selectSafetyActivityList(safetyActivity);
        safetyActivities.stream().forEach(item -> {
            R<SysUser> user = remoteUserService.getUserById(Long.valueOf(item.getCompere()));
            item.setCompere(user.getData().getNickName());
        });
        return safetyActivities;
    }

    /**
     * 新增安全活动记录
     * 
     * @param safetyActivity 安全活动记录
     * @return 结果
     */
    @Override
    public int insertSafetyActivity(SafetyActivity safetyActivity)
    {
        safetyActivity.setCreateTime(DateUtils.getNowDate());
        safetyActivity.setAttendanceNumber(0);
        return safetyActivityMapper.insertSafetyActivity(safetyActivity);
    }

    /**
     * 修改安全活动记录
     * 
     * @param safetyActivity 安全活动记录
     * @return 结果
     */
    @Override
    public int updateSafetyActivity(SafetyActivity safetyActivity)
    {
        safetyActivity.setUpdateTime(DateUtils.getNowDate());
        return safetyActivityMapper.updateSafetyActivity(safetyActivity);
    }

    /**
     * 批量删除安全活动记录
     * 
     * @param ids 需要删除的安全活动记录主键
     * @return 结果
     */
    @Override
    public int deleteSafetyActivityByIds(Long[] ids)
    {
        return safetyActivityMapper.deleteSafetyActivityByIds(ids);
    }

    /**
     * 删除安全活动记录信息
     * 
     * @param id 安全活动记录主键
     * @return 结果
     */
    @Override
    public int deleteSafetyActivityById(Long id)
    {
        return safetyActivityMapper.deleteSafetyActivityById(id);
    }
}
